﻿<%@ Page Title="" Language="C#" MasterPageFile="~/TsSite.Master" AutoEventWireup="true" CodeBehind="Planning.aspx.cs" Inherits="TireService.Web.View.ServiceView.Planning" %>

<%@ Register Assembly="DevExpress.Web.v11.1, Version=11.1.12.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a" Namespace="DevExpress.Web.ASPxCallbackPanel" TagPrefix="dx" %>
<%@ Register Assembly="DevExpress.Web.v11.1, Version=11.1.12.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a" Namespace="DevExpress.Web.ASPxHiddenField" TagPrefix="dx" %>
<%@ Register Assembly="DevExpress.Web.v11.1, Version=11.1.12.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a" Namespace="DevExpress.Web.ASPxPanel" TagPrefix="dx" %>
<%@ Register Assembly="DevExpress.Web.v11.1, Version=11.1.12.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a" Namespace="DevExpress.Web.ASPxCallback" TagPrefix="dx" %>
<%@ Register Assembly="DevExpress.Web.v11.1, Version=11.1.12.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a" Namespace="DevExpress.Web.ASPxPopupControl" TagPrefix="dx" %>
<%@ Register Assembly="DevExpress.Web.ASPxGridView.v11.1, Version=11.1.12.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a" Namespace="DevExpress.Web.ASPxGridView" TagPrefix="dx" %>
<%@ Register Assembly="DevExpress.Web.ASPxPivotGrid.v11.1, Version=11.1.12.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a" Namespace="DevExpress.Web.ASPxPivotGrid" TagPrefix="dx" %>
<%@ Register assembly="DevExpress.Web.ASPxEditors.v11.1, Version=11.1.12.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a" namespace="DevExpress.Web.ASPxEditors" tagprefix="dx" %>

<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">

    <table cellpadding="0" cellspacing="2" border="0">
        <tr>
            <td>
                <img id="imgServicePlanning" alt="" src="~/Images/Medium/stopwatch.png" runat="server" style="width: 32px; height: 32px" />
            </td>
            <td valign="middle">
                <h3><asp:Label ID="lblServicePlanning" runat="server" Text="Planlægning"></asp:Label></h3>
            </td>
        </tr>
    </table>

    <script type="text/javascript">
        // Function for drilling down and show planned service for a specific day and service car
        function ShowDrillDown() {
            var mainTable = pgServiceCarCapacity.GetMainTable();
            DrillDownWindow.Show();
        }

        function UpdateContainer() {
            gvCarNeedService.PerformCallback();
            pgServiceCarCapacity.PerformCallback();
        }

        // Change gridview based on selected carstatus
        function UpdateCarStatus() {
            gvCarNeedService.PerformCallback();
            pgServiceCarCapacity.PerformCallback();
        }

    </script>

    <!-- Javascript for generating timeslots -->
    <script type="text/javascript" language="javascript">

        function PrepareGenerateTimeslots() {
            // Show modal popup
            pcCreateTimeslots.Show();

            // Generate UI through callback
            cbPanelCreateTimeslots.PerformCallback();
        }

        function SaveCreateTimeslots() {
            // Validate values
            ddlDate.Validate();
            rbtnServiceCar.Validate();
            txtStartingTime.Validate();
            txtLatestEndTime.Validate();
            txtSlotInterval.Validate();
            txtGenerateTimeslotOverlap.Validate();

            var isFormValid = ASPxClientEdit.ValidateGroup("GenerateTimeslot");
            if (isFormValid) {
                // Get values for timeslots
                var values = rbtnServiceCar.GetValue() + ',' + ddlDate.GetValue() + ',' + txtStartingTime.GetText() + ',' + txtLatestEndTime.GetText() + ',' + txtSlotInterval.GetText() + ',' + txtGenerateTimeslotOverlap.GetText() + ',' + cbSelectedWholePeriod.GetChecked() + ',' + txtSelectedStartDate.GetText() + ',' + txtSelectedEndDate.GetText();

                // Do call back to generate timeslots
                callBackCreateTimeslots.PerformCallback(values);
            } 
        }

        function OnCallbackCreateTimeslotsComplete() {
            // Hide modal popup
            pcCreateTimeslots.Hide();

            // Refresh pivottable with service car capacity overview
            pgServiceCarCapacity.PerformCallback();

            // Show user message
            alert('Tomme kørselstider oprettet');
        }

        function CreateSingleTimeslot() {
            // Validate values
            txtOverlap.Validate();
            txtDuration.Validate();

            var isFormValid = ASPxClientEdit.ValidateGroup("GenerateSingleTimeslot");
            if (isFormValid) {
                

                // Set focus on first row
                GridView.SetFocusedRowIndex(0);

                // Get first row values and trigger event ShowPlanningSchedule
                GridView.GetRowValues(GridView.GetFocusedRowIndex(), 'ServiceCarId;ScheduleDate', SaveTimeslot);
            } 
            
        }

        function SaveTimeslot(values) {
            if (values == null) return;
            if (values.length == 0) return;

            var scheduleDate = new Date(values[1]);
            var stringDate = scheduleDate.getDate() + "-" + (1 + scheduleDate.getMonth()) + "-" + scheduleDate.getFullYear();

            // Get values for timeslot (servicecarid, scheduledate, duration, overlap)
            var input = values[0] + ',' + stringDate + ',' + txtDuration.GetText() + ',' + txtOverlap.GetText();

            // Do call back to create single timeslot
            callCreateSingleTimeslot.PerformCallback(input);
        }

        function OnCallbackCreateSingleTimeslotComplete() {
            // Refresh gridview
            GridView.PerformCallback('D');
            pgServiceCarCapacity.PerformCallback();
        }

    </script>

    <!-- Javascript for booking service -->
    <script language="javascript" type="text/javascript">

        var servicescheduledetailid = 0;

        function BookService(serviceid) {

            // Set detail id based on clicked row
            servicescheduledetailid = serviceid;

            // Get carid and run book selected car function
            gvCarNeedService.GetRowValues(gvCarNeedService.GetFocusedRowIndex(), 'CarId', BookSelectedCar);
        }

        function BookSelectedCar(values) {
            if (values == null | values.length == 0) {
                alert('Ingen bil valgt - venligst vælg en bil og book igen.');
            }
            else {
                
                var input = '';

                // Check if user has choosen to use other address - if yes, prepare extra input
                if (cbOtherAddress.GetChecked() == true)
                {
                    // Prepare input values for callback - add other address info to values
                    input = values + ',' + servicescheduledetailid + ',' + cbOtherAddress.GetChecked() + ',' + txtOtherAddress.GetText() + ',' + txtOtherZipCode.GetText() + ',' + txtOtherCity.GetText();
                }
                else 
                {
                    // Prepare input values for callback
                    input = values + ',' + servicescheduledetailid + ',' + cbOtherAddress.GetChecked();
                }

                // Run callback function to book selected car
                callBookService.PerformCallback(input);
            }
        }

        function DeleteBookedService(serviceid) {
            
            // Run callback function to delete booked service
            callDeleteBookedService.PerformCallback(serviceid);
        }

        function OnCallbackBookServiceComplete() {

            // Reset values
            servicescheduledetailid = 0;

            // Refresh gridviews
            GridView.PerformCallback('D');
            gvCarNeedService.PerformCallback();

            // Clear form fields
            cbSecondaryAddress.SetChecked(false);
            cbCustomerConfirmed.SetChecked(false);
            cbOtherAddress.SetChecked(false);
            txtOtherAddress.SetText('');
            txtOtherZipCode.SetText('');
            txtOtherCity.SetText('');
        }

        function OnCallbackDeleteBookedServiceComplete() {

            // Reset values
            servicescheduledetailid = 0;

            // Refresh gridviews
            GridView.PerformCallback('D');
            gvCarNeedService.PerformCallback();
        }

        function CallBackBookServiceError() {

            // Reset values
            servicescheduledetailid = 0;

            alert('Fejl opstod - venligst prøv igen');
        }

        function CallBackDeleteBookedServiceError() {
            
            // Reset values
            servicescheduledetailid = 0;

            alert('Fejl opstod - venligst prøv igen');
        }

    </script>

    <table>
        <tr>
            <td>Lager</td>
            <td>Startdato</td>
            <td>Slutdato</td>
            <td></td>
            <td></td>
            <td></td>
        </tr>
        <tr>
            <td>
                <dx:ASPxComboBox ID="ddlContainer" ClientInstanceName="ddlContainer" runat="server">
                    <ClientSideEvents SelectedIndexChanged="function(s, e) { UpdateContainer()  }" />
                </dx:ASPxComboBox>
            </td>
            <td>
                <dx:ASPxDateEdit ID="txtSelectedStartDate" ClientInstanceName="txtSelectedStartDate" runat="server">
                    <ClientSideEvents DateChanged="function(s, e) { pgServiceCarCapacity.PerformCallback()  }" />
                </dx:ASPxDateEdit>
            </td>
            <td>
                <dx:ASPxDateEdit ID="txtSelectedEndDate" ClientInstanceName="txtSelectedEndDate" runat="server">
                    <ClientSideEvents DateChanged="function(s, e) { pgServiceCarCapacity.PerformCallback()  }" />
                </dx:ASPxDateEdit>
            </td>
            <td>
                <dx:ASPxButton ID="btnCreateTimeslots" ClientInstanceName="btnCreateTimeslots" runat="server" Text="Opret tomme kørselstider" AutoPostBack="False" UseSubmitBehavior="False">
                    <ClientSideEvents Click="function(s, e) { pcCreateTimeslots.Show() }" />
                </dx:ASPxButton>            
            </td>
            <td>
                <dx:ASPxButton ID="btnClearSelectedCarFilter" runat="server" 
                    Text="Fjern bil filter" Visible="false" 
                    onclick="btnClearSelectedCarFilter_Click">
                </dx:ASPxButton>            
            </td>
            <td>
                <asp:Label ID="lblPrimary" Font-Size="Small" runat="server" Text="Primær adresse" BorderColor="Black" BorderWidth="1"></asp:Label><br />
                <asp:Label ID="lblSecondary" Font-Size="Small" runat="server" Text="Sekundær adresse" Width="" BackColor="Bisque" BorderColor="Black" BorderWidth="1"></asp:Label>
            </td>
            <td>
                <dx:ASPxComboBox ID="ddlCarStatus" ClientInstanceName="ddlCarStatus" runat="server">
                    <Items>
                        <dx:ListEditItem Value="30" Selected="true" Text="Skal have skiftet hjul" />
                        <dx:ListEditItem Value="60" Text="Skal have hentet hjul" />
                        <dx:ListEditItem Value="80" Text="Skal have leveret hjul tilbage" />
                    </Items>
                    <ClientSideEvents SelectedIndexChanged="function(s, e) { UpdateCarStatus()  }" />
                </dx:ASPxComboBox>
            </td>
        </tr>
    </table>
    <hr />
    <!-- Gridview with cars that need service -->
    <dx:ASPxGridView ID="gvCarNeedService" runat="server" 
        Caption="Biler afventende hjulskift service" 
        ClientInstanceName="gvCarNeedService" Width="100%"
        KeyFieldName="TireSetId" AutoGenerateColumns="False" EnableCallBacks="True"
        OnHtmlRowPrepared="gvCarNeedService_HtmlRowPrepared"  
        OnCustomCallback="gvCarNeedService_CustomCallback">
        <SettingsLoadingPanel Text="Henter&amp;hellip;" />
        <Border BorderWidth="0px" />
        <Settings ShowVerticalScrollBar="true" ShowHeaderFilterButton="true" ShowGroupPanel="true" ShowFilterRow="true" />
        <SettingsPager AlwaysShowPager="False" PageSize="10" Position="Bottom">
            <Summary 
                AllPagesText="Sider: {0} - {1} ({2} biler)" 
                Text="Side {0} af {1} ({2} biler)" />
        </SettingsPager>
        <SettingsBehavior ProcessFocusedRowChangedOnServer="false" AllowFocusedRow="true" ConfirmDelete="True" AllowGroup="true" AllowDragDrop="false" />
        <Columns>
            <dx:GridViewCommandColumn ShowSelectCheckbox="True" VisibleIndex="0">
                    <HeaderTemplate>
                        <input type="checkbox" onclick="gvCarNeedService.SelectAllRowsOnPage(this.checked);" style="vertical-align:middle;" title="Vælg/Fravælg alle linjer på siden"></input>
                    </HeaderTemplate>
                    <HeaderStyle Paddings-PaddingTop="1" Paddings-PaddingBottom="1" 
                        HorizontalAlign="Center">
                    <Paddings PaddingTop="1px" PaddingBottom="1px"></Paddings>
                    </HeaderStyle>
            </dx:GridViewCommandColumn>
            <dx:GridViewDataColumn FieldName="CarId" Visible="false" VisibleIndex="4" Caption="CarId">
            </dx:GridViewDataColumn>
            <dx:GridViewDataColumn FieldName="CustomerId" Visible="false" VisibleIndex="4" Caption="CustomerId">
            </dx:GridViewDataColumn>
            <dx:GridViewDataColumn FieldName="TireSetId" Visible="false" VisibleIndex="4" Caption="TireSetId">
            </dx:GridViewDataColumn>
            <dx:GridViewDataColumn FieldName="ContainerId" Visible="false" VisibleIndex="4" Caption="ContainerId">
            </dx:GridViewDataColumn>
            <dx:GridViewDataColumn FieldName="Address" Visible="false" VisibleIndex="4" Caption="Address">
            </dx:GridViewDataColumn>
            <dx:GridViewDataColumn FieldName="ZipCode" Visible="false" VisibleIndex="4" Caption="ZipCode">
            </dx:GridViewDataColumn>
            <dx:GridViewDataColumn FieldName="City" Visible="false" VisibleIndex="4" Caption="City">
            </dx:GridViewDataColumn>
            <dx:GridViewDataColumn FieldName="CountryId" Visible="false" VisibleIndex="4" Caption="CountryId">
            </dx:GridViewDataColumn>
            <dx:GridViewDataColumn FieldName="Longitude" Visible="false" VisibleIndex="4" Caption="Longitude">
            </dx:GridViewDataColumn>
            <dx:GridViewDataColumn FieldName="Latitude" Visible="false" VisibleIndex="4" Caption="Latitude">
            </dx:GridViewDataColumn>
            <dx:GridViewDataColumn FieldName="LongitudePrimary" Visible="false" VisibleIndex="4" Caption="LongitudePrimary">
            </dx:GridViewDataColumn>
            <dx:GridViewDataColumn FieldName="LatitudePrimary" Visible="false" VisibleIndex="4" Caption="LatitudePrimary">
            </dx:GridViewDataColumn>
            <dx:GridViewDataColumn FieldName="LongitudeSecondary" Visible="false" VisibleIndex="4" Caption="LongitudeSecondary">
            </dx:GridViewDataColumn>
            <dx:GridViewDataColumn FieldName="LatitudeSecondary" Visible="false" VisibleIndex="4" Caption="LatitudeSecondary">
            </dx:GridViewDataColumn>
            <dx:GridViewDataHyperLinkColumn FieldName="CustomerId" VisibleIndex="3" Caption="Kundenr">
                <PropertiesHyperLinkEdit NavigateUrlFormatString="~/View/CustomerView/EditCustomerData.aspx?CustomerId={0}" TextField="CustomerId" Target="_blank">
                </PropertiesHyperLinkEdit>
            </dx:GridViewDataHyperLinkColumn>
            <dx:GridViewDataTextColumn FieldName="ContainerNumber" VisibleIndex="5" Caption="Lager">
            </dx:GridViewDataTextColumn>
            <dx:GridViewDataTextColumn FieldName="CarBrandDescription" VisibleIndex="6" Caption="Bilmærke">
            </dx:GridViewDataTextColumn>
            <dx:GridViewDataColumn FieldName="Model" VisibleIndex="7" Caption="Model">
            </dx:GridViewDataColumn>
            <dx:GridViewDataColumn FieldName="RegistrationNumber" VisibleIndex="8" Caption="Reg.nr.">
            </dx:GridViewDataColumn>
            <dx:GridViewDataColumn FieldName="PrimaryAddress" VisibleIndex="9" Caption="Adresse">
            </dx:GridViewDataColumn>
            <dx:GridViewDataColumn FieldName="PrimaryZipCode" VisibleIndex="9" Caption="Postnr">
            </dx:GridViewDataColumn>
            <dx:GridViewDataColumn FieldName="PrimaryCity" VisibleIndex="10" Caption="By">
            </dx:GridViewDataColumn>
            <dx:GridViewDataColumn FieldName="CustomerCountryId" VisibleIndex="10" Caption="CustomerCountryId" Visible="false">
            </dx:GridViewDataColumn>
            <dx:GridViewDataColumn FieldName="SecondaryAddress" VisibleIndex="10" Caption="Sek. Adr" Visible="true">
            </dx:GridViewDataColumn>          
            <dx:GridViewDataColumn FieldName="SecondaryZipCode" VisibleIndex="10" Caption="Sek. Postnr" Visible="true">
            </dx:GridViewDataColumn>          
            <dx:GridViewDataColumn FieldName="SecondaryCity" VisibleIndex="10" Caption="Sek. By" Visible="true">
            </dx:GridViewDataColumn>
            <dx:GridViewDataColumn FieldName="Distance" VisibleIndex="11" Caption="Km pri." ToolTip="Afstand fra lager til kundens primære adresse">
            </dx:GridViewDataColumn>
            <dx:GridViewDataColumn FieldName="DistanceSecondary" VisibleIndex="11" Caption="Km sek." ToolTip="Afstand fra lager til kundens sekundære adresse">
            </dx:GridViewDataColumn>
            <dx:GridViewDataColumn FieldName="OnPrimaryAddressInPrimeTime" Visible="false" VisibleIndex="11">
            </dx:GridViewDataColumn>
        </Columns>                                            
    </dx:ASPxGridView>
    <hr />
           
    <input runat="server" id="ColumnIndex" type="hidden" enableviewstate="true" />
    <input runat="server" id="RowIndex" type="hidden" enableviewstate="true" />
    <dx:ASPxPivotGrid ID="pgServiceCarCapacity" runat="server" 
        ClientInstanceName="pgServiceCarCapacity" Width="100%" 
        EnableCallBacks="true" 
        OnCustomCallback="pgServiceCarCapacity_CustomCallback">
        <Fields>
            <dx:PivotGridField Area="RowArea" AreaIndex="0" FieldName="ServiceCarId" ID="fieldServiceCarId" Caption="Servicevogn" />
            <dx:PivotGridField Area="ColumnArea" AreaIndex="1" FieldName="ScheduleDate" 
                ID="fieldScheduleDate" Caption="Dag" GroupInterval="DateDayOfWeek" 
                UnboundFieldName="fieldScheduleDate" />
            <dx:PivotGridField Area="ColumnArea" AreaIndex="0" FieldName="ScheduleDate" 
                ID="PivotGridField1" Caption="Dato" GroupInterval="Date" 
                UnboundFieldName="PivotGridField1" />
            <%--<dx:PivotGridField Area="ColumnArea" AreaIndex="1" FieldName="ScheduleDetailTypeId" ID="fieldDetailType" />--%>
            <dx:PivotGridField Area="ColumnArea" AreaIndex="2" 
                FieldName="ScheduleDetailTypeDescription" ID="PivotGridField2" />
            <%--<dx:PivotGridField Area="ColumnArea" AreaIndex="1" FieldName="ScheduleDetailTypeId" ID="fieldScheduleDetailTypeId" Caption="Type" />--%>
            <dx:PivotGridField Area="DataArea" AreaIndex="0" SummaryType="Count" FieldName="ServiceCarScheduleDetailId" ID="fieldServiceCarScheduleDetailId" Caption="Kapacitet" TotalsVisibility="None" />
            <%--<dx:PivotGridField ID="fieldPercents" Area="DataArea" AreaIndex="1" Caption="Opret" FieldName="ServiceCarScheduleDetailId" SummaryDisplayType="PercentOfColumn" />--%>
            <%--<dx:PivotGridField ID="fieldPercents" Area="DataArea" AreaIndex="1" Caption="Opret" FieldName="ScheduleDetailTypeId" />--%>
        </Fields>
    </dx:ASPxPivotGrid>                            

    <!-- Javascript of planning action dropdown list -->
    <script language="javascript" type="text/javascript">
                
        // Function that handles actions selected in planning action dropdown list
        function PlanningActionClicked() {

            // Get selected action from dropdownlist
            var id = ddlAction.GetValue();

            if (id != null && id != 0) {

                // Manual editing of schedule
                if (id == 1) {
                    // Get id, address, zipcode, city, start and endtime and run initialize manual servicedetail edit function
                    GridView.GetRowValues(GridView.GetFocusedRowIndex(), 'ServiceCarScheduleDetailId;ToAddress;ToZipCode;ToCity;StartTime;EndTime', initializeServiceDetailEdit);

                    // Show modal popup
                    pcPlanningManualEdit.Show();
                }

                // Add/Edit note
                if (id == 2) {
                    ShowNote();
                }

                // Show planning schedule
                if (id == 3) {
                    // Set focus on first row
                    GridView.SetFocusedRowIndex(0);
                            
                    // Get first row values and trigger event ShowPlanningSchedule
                    GridView.GetRowValues(GridView.GetFocusedRowIndex(), 'ContainerId;ScheduleDate', ShowPlanningSchedule);
                }

                // Request approval for selected customers
                if (id == 4) {
                    // Get selected items in gridview and trigger event RequestApprovalSelectedCustomers 
                    GridView.GetSelectedFieldValues('ServiceCarScheduleDetailId', RequestApprovalSelectedCustomers);
                }

                // Set selected as approved
                if (id == 5) {
                    // Get selected items in gridview and trigger event SetSelectedAsApproved
                    GridView.GetSelectedFieldValues('ServiceCarScheduleDetailId', SetSelectedAsApproved);
                }

                // Remove approval from selected
                if (id == 6) {
                    // Get selected items in gridview and trigger event RemoveApprovalOnSelected
                    GridView.GetSelectedFieldValues('ServiceCarScheduleDetailId', RemoveApprovalOnSelected);
                }

                // Show googleview
                if (id == 7) {

                    // Get latitude and longitude and run initialize googleview function
                    GridView.GetRowValues(GridView.GetFocusedRowIndex(), 'ToLatitude;ToLongitude', initializeGoogleView);

                    // Show modal popup
                    pcPlanningActionWindows.Show();

                    // Change header on popup
                    pcPlanningActionWindows.SetHeaderText('Googlemap og streetview');

                    // Show googleview panel and hide rest of panels
                    pGoogleView.SetVisible(true);
                    pGoogleDirection.SetVisible(false);
                }

                // Show google directions
                if (id == 8) {

                    // Set focus on first row
                    GridView.SetFocusedRowIndex(0);

                    // Get first row values and trigger event generate URL
                    GridView.GetRowValues(GridView.GetFocusedRowIndex(), 'ServiceCarId;ScheduleDate', RedirectToURL);


//                    initializeGoogleDirection();

//                    // Show modal popup
//                    pcPlanningActionWindows.Show();

//                    // Change header on popup
//                    pcPlanningActionWindows.SetHeaderText('Kørselsvejledning');

//                    // Show google directions panel and hide rest of panels
//                    pGoogleView.SetVisible(false);
//                    pGoogleDirection.SetVisible(true);
                }

                // Block selected bookings (only if free/not allocated)
                if (id == 10) {
                    // Get selected items in gridview and trigger event AddBlockOnSelected
                    GridView.GetSelectedFieldValues('ServiceCarScheduleDetailId', AddBlockOnSelected);
                }
            }
            else 
            {
                alert('Ingen handling valgt');
            }
        }

        // Show edit/add note
        function ShowNote() {
            // Get detail id and note
            GridView.GetRowValues(GridView.GetFocusedRowIndex(), 'Note', initializeEditNote);

            // Show modal popup
            pcPlanningNote.Show();
        }

        // Create URL to googlemaps directions
        function RedirectToURL(values) {
            if (values == null) return;
            if (values.length == 0) return;

            var scheduleDate = new Date(values[1]);
            var stringDate = scheduleDate.getDate() + "-" + (1 + scheduleDate.getMonth()) + "-" + scheduleDate.getFullYear();

            // Get values for timeslot (servicecarid, scheduledate)
            var input = values[0] + ',' + stringDate;

            // Do call back to create google directions url
            callGenerateURLGoogleDirection.PerformCallback(input);
        }

        // Show servicedetail info for editing
        function initializeServiceDetailEdit(values) {
            if (values == null) return;
            if (values.length == 0) return;

            txtAddress.SetText(values[1]);
            txtZipCode.SetText(values[2]);
            txtCity.SetText(values[3]);
            txtStartTime.SetText(values[4]);
            txtEndTime.SetText(values[5]);
        }

        // Show note values in UI and store detail id in hidden field
        function initializeEditNote(values) {
            if (values == null) 
            {
                txtPlanningNote.SetText('');
                return;
            }
            else {

                txtPlanningNote.SetText(values[0]);
                txtPlanningNote.Focus();
            }  
        }

        // Perform callback and save service detail
        function SaveServiceDetailClicked() {

            if (txtLatitude.GetText() == '' | txtLongitude.GetText() == '') {
                alert('Venligst klik hen koordinator først, for at valider adresse');
            } else {
                // Get detail id
                var id = GridView.GetRowKey(GridView.GetFocusedRowIndex());

                // Get values for service detail
                var values = id + ',' + txtAddress.GetText() + ',' + txtZipCode.GetText() + ',' + txtCity.GetText() + ',' + txtStartTime.GetText() + ',' + txtEndTime.GetText() + ',' + txtLatitude.GetText() + ',' + txtLongitude.GetText();

                callBackSaveServiceDetail.PerformCallback(values);
            }
        }

        // Perform callback and save note
        function SaveNoteClicked() {
            var id = GridView.GetRowKey(GridView.GetFocusedRowIndex());
            var values = id + ',' + txtPlanningNote.GetText();
            callBackSaveNote.PerformCallback(values);
        }

        // Show popup with planning schedule
        function ShowPlanningSchedule(values) {
            if (values == null) return;
            if (values.length == 0) return;

            var scheduleDate = new Date(values[1]);
            var stringDate = scheduleDate.getDate() + "-" + (1 + scheduleDate.getMonth()) + "-" + scheduleDate.getFullYear();

            window.open('../../Reports/View/ServiceCarScheduleReportView.aspx?ContainerId=' + values[0] + "&ScheduleDate=" + stringDate, 'Kørselsskema');

            // Deselect all lines
            GridView.SelectAllRowsOnPage(false);
        }

        // Perform callback that sends request for booking confirmation for selected customers/bookings
        function RequestApprovalSelectedCustomers(selectedValues) {
            if (selectedValues.length == 0) return;
                    
            callBackRequestApprovalSelectedCustomers.PerformCallback(selectedValues);
        }

        // Perform callback that updates booked services as customer approved for selected customers/bookings
        function SetSelectedAsApproved(selectedValues) {
            if (selectedValues.length == 0) return;

            callBackSetSelectedAsApproved.PerformCallback(selectedValues);
        }

        // Perform callback that updates booked services as NOT customer approved for selected customers/bookings
        function RemoveApprovalOnSelected(selectedValues) {
            if (selectedValues.length == 0) return;

            callBackRemoveApprovalOnSelected.PerformCallback(selectedValues);
        }

        // Perform callback that updates selected bookings as blocked if they is free/not allocated
        function AddBlockOnSelected(selectedValues) {
            if (selectedValues.length == 0) return;

            callBackAddBlockOnSelected.PerformCallback(selectedValues);
        }

        function OnCallbackRequestApprovalSelectedCustomersComplete(s, e) {
            alert('Anmodning om godkendelse sendt pr. email til valgte');
        }

        function OnCallbackSetSelectedAsApprovedComplete(s, e) {
            GridView.PerformCallback('D');
            
            alert('Valgte angivet som godkendte');
        }

        function OnCallbackRemoveApprovalOnSelectedComplete(s, e) {
            GridView.PerformCallback('D');

            alert('Valgte angivet som IKKE godkendte');
        }

        function OnCallbackAddBlockOnSelectedComplete(s, e) {
            GridView.PerformCallback('D');

            alert('Valgte angivet som blokeret');
        }

        function OnCallbackSaveServiceDetailComplete(s, e) {
            // Hide modal popup
            pcPlanningManualEdit.Hide();

            GridView.PerformCallback('D');

            alert('Data for booking blev gemt');
        }

        function OnCallbackSaveNoteComplete(s, e) {
            // Hide modal popup
            pcPlanningNote.Hide();

            GridView.PerformCallback('D');
        }

        function OnCallbackGenerateURLGoogleDirectionComplete(s, e) {

            if (e.result == '') return;

            window.open(e.result);

            // Deselect all lines
            GridView.SelectAllRowsOnPage(false);
        }


        function CallBackError(s, e) {
            alert('Fejl opstod - prøv venligst igen');
        }

    </script>

    <!-- Javascript for Google map and streetview Modal popup view -->
    <script src="http://maps.google.com/?file=api&amp;v=2.x&amp;key=ABQIAAAAOqg0zdZdLRm2WH8lJpFDLxRBYr_GQowC8JJyghooYbwZzCFRqRS3_8Vqwz9Fzn2YR5-Z-atDW-OUxg" type="text/javascript"></script>
    <script src="http://maps.google.com/maps/api/js?sensor=false" type="text/javascript"></script>
    <script type="text/javascript">

        function initializeGoogleView(values) {
            if (values.length == 0) return;

            // Initiate google map
            var fenway = new google.maps.LatLng((values[0] / 100000), (values[1] / 100000));
            var mapOptions = {
                center: fenway,
                zoom: 14,
                mapTypeId: google.maps.MapTypeId.ROADMAP
            };
            var map = new google.maps.Map(
            document.getElementById("map_canvas"), mapOptions);
            var panoramaOptions = {
                position: fenway,
                pov: {
                    heading: 34,
                    pitch: 10,
                    zoom: 1
                }
            };
            var panorama = new google.maps.StreetViewPanorama(document.getElementById("pano"), panoramaOptions);
            map.setStreetView(panorama);
        }
    </script>

    <!-- Javascript for Google directions -->
    <script type="text/javascript">
        var directionDisplay;
        var directionsService = new google.maps.DirectionsService();
        var map;
        var waypts = [];

        function initializeGoogleDirection() {
            directionsDisplay = new google.maps.DirectionsRenderer();
            var centercoordinate = new google.maps.LatLng(56.4605827331543, 10.036539077758789);
            var myOptions = {
                zoom: 6,
                mapTypeId: google.maps.MapTypeId.ROADMAP,
                center: centercoordinate
            }
            map = new google.maps.Map(document.getElementById("directionmap_canvas"), myOptions);
            directionsDisplay.setMap(map);
                    
            // Clear waypoints
            waypts.length = 0;
            waypts = [];

            // Calculate directions
            calcRoute(false);
        }

        function AddWayPoint(value) {
            var LatLong = (value[0] / 100000) + ", " + (value[1] / 100000);

            // Check coordinates exists
            if (value[0] != null && value[1] != null) {
                // Add waypoint
                waypts.push({
                    location: LatLong,
                    stopover: true
                });
            }
        }

        function calcRoute(optimize) {
            // Select all rows in gridview
            var count = GridView.GetVisibleRowsOnPage(); 
                    
            // Add coordinates for each row in gridview
            for (var i = 0; i < count; i++) {
                GridView.GetRowValues(i, 'ToLatitude;ToLongitude', AddWayPoint);
            }
                    
            window.setTimeout(function (a,b) {timer(optimize);}, 3000);
        }

        function timer(optimize) {
            // Get start and end location from container location
//                    var container = ddlContainer.GetSelectedItem();
//                    var containerLat = container.GetColumnText(5);
//                    var containerLong = container.GetColumnText(6);

//                    var start = (containerLat / 100000) + ", " + (containerLong / 100000);

            var start = waypts[0].location;
            var end = waypts[waypts.length - 1].location;
                    
            // Remove start and end from waypoints
            waypts.splice(0, 1);
            waypts.splice(waypts.length - 1, 1);

            var request = {
                origin: start,
                destination: start,
                waypoints: waypts,
                optimizeWaypoints: optimize,
                travelMode: google.maps.DirectionsTravelMode.DRIVING
            };
            directionsService.route(request, function (response, status) {
                if (status == google.maps.DirectionsStatus.OK) {
                    directionsDisplay.setDirections(response);
                    var route = response.routes[0];
                    var summaryPanel = document.getElementById("directions_panel");
                    summaryPanel.innerHTML = "";
                    // For each route, display summary information.
                    for (var i = 0; i < route.legs.length; i++) {
                        var routeSegment = i + 1;
                        summaryPanel.innerHTML += "<b>Rute: " + routeSegment + "</b><br />";
                        summaryPanel.innerHTML += route.legs[i].start_address + " til ";
                        summaryPanel.innerHTML += route.legs[i].end_address + "<br />";
                        summaryPanel.innerHTML += route.legs[i].duration.text + "<br />";
                        summaryPanel.innerHTML += route.legs[i].distance.text + "<br /><br />";
                    }
                }
            });
        }

    </script>

    <!-- Javascript for Google geocoder finding latitude and longitude -->
    <script type="text/javascript">

        // Function that updates UI with latitude and longitude coordinates for address
        function GetLatLong() {
            // Get longitude and latitude for address
            showAddress(txtAddress.GetText() + ', ' + txtZipCode.GetText() + ' ' + txtCity.GetText() + ', Danmark');
        }

        // Function that call google geocoder and get latitude and longitude coordinates for address
        function showAddress(address) {
            geocoder = new GClientGeocoder();
                    
            if (geocoder) {
                geocoder.getLatLng(
                    address,
                    function (point) {
                        if (!point) {
                            alert(address + " blev ikke fundet");
                        } else {
                            document.getElementById("lat").innerHTML = point.lat().toFixed(5);
                            document.getElementById("lng").innerHTML = point.lng().toFixed(5);
                            txtLatitude.SetText(point.lat().toFixed(5));
                            txtLongitude.SetText(point.lng().toFixed(5));
                        }
                    }
                );
            }
        }
    </script>

    <dx:ASPxCallback ID="callBackRequestApprovalSelectedCustomers" ClientInstanceName="callBackRequestApprovalSelectedCustomers" runat="server" OnCallback="callBackRequestApprovalSelectedCustomers_Callback">
        <ClientSideEvents CallbackError="CallBackError" CallbackComplete="OnCallbackRequestApprovalSelectedCustomersComplete" />
    </dx:ASPxCallback>

    <dx:ASPxCallback ID="callBackSetSelectedAsApproved" ClientInstanceName="callBackSetSelectedAsApproved" runat="server" OnCallback="callBackSetSelectedAsApproved_Callback">
        <ClientSideEvents CallbackError="CallBackError" CallbackComplete="OnCallbackSetSelectedAsApprovedComplete" />
    </dx:ASPxCallback>

    <dx:ASPxCallback ID="callBackRemoveApprovalOnSelected" ClientInstanceName="callBackRemoveApprovalOnSelected" runat="server" OnCallback="callBackRemoveApprovalOnSelected_Callback">
        <ClientSideEvents CallbackError="CallBackError" CallbackComplete="OnCallbackRemoveApprovalOnSelectedComplete" />
    </dx:ASPxCallback>

    <dx:ASPxCallback ID="callBackAddBlockOnSelected" ClientInstanceName="callBackAddBlockOnSelected" runat="server" OnCallback="callBackAddBlockOnSelected_Callback">
        <ClientSideEvents CallbackError="CallBackError" CallbackComplete="OnCallbackAddBlockOnSelectedComplete" />
    </dx:ASPxCallback>

    <dx:ASPxCallback ID="callBackSaveServiceDetail" ClientInstanceName="callBackSaveServiceDetail" runat="server" OnCallback="callBackSaveServiceDetail_Callback">
        <ClientSideEvents CallbackError="CallBackError" CallbackComplete="OnCallbackSaveServiceDetailComplete" />
    </dx:ASPxCallback>

    <dx:ASPxCallback ID="callBackSaveNote" ClientInstanceName="callBackSaveNote" runat="server" OnCallback="callBackSaveNote_Callback">
        <ClientSideEvents CallbackError="CallBackError" CallbackComplete="OnCallbackSaveNoteComplete" />
    </dx:ASPxCallback>

    <dx:ASPxCallback ID="callBookService" ClientInstanceName="callBookService" runat="server" OnCallback="callBookService_Callback">
        <ClientSideEvents CallbackError="CallBackBookServiceError" CallbackComplete="OnCallbackBookServiceComplete" />
    </dx:ASPxCallback>

    <dx:ASPxCallback ID="callDeleteBookedService" ClientInstanceName="callDeleteBookedService" runat="server" OnCallback="callDeleteBookedService_Callback">
        <ClientSideEvents CallbackError="CallBackDeleteBookedServiceError" CallbackComplete="OnCallbackDeleteBookedServiceComplete" />
    </dx:ASPxCallback>

    <dx:ASPxCallback ID="callGenerateURLGoogleDirection" ClientInstanceName="callGenerateURLGoogleDirection" runat="server" OnCallback="callGenerateURLGoogleDirection_Callback">
        <ClientSideEvents CallbackError="CallBackError" CallbackComplete="OnCallbackGenerateURLGoogleDirectionComplete" />
    </dx:ASPxCallback>

    <!-- Modalpopup: Overview of car capacity for selected servicecar and day in pivottable -->
    <dx:ASPxPopupControl ID="pcServiceCarCapacity" Modal="false" runat="server" Height="1px" AutoUpdatePosition="true"
        PopupHorizontalAlign="WindowCenter" PopupVerticalAlign="WindowCenter" 
        AllowDragging="True" ClientInstanceName="DrillDownWindow" Left="200" Top="200"
        CloseAction="CloseButton" Width="153px" HeaderText="Kapacitets oversigt">
        <ContentCollection>
            <dx:PopupControlContentControl runat="server">
                <div style="font-family: Tahoma; font-size: 9pt; font-weight: normal; color: #f15e34">
                    &nbsp;<asp:Literal ID="lModalPopupMessage" runat="server"></asp:Literal>
                </div>
                <table>
                    <tr>
                        <td colspan="2">
                            <dx:ASPxComboBox ID="ddlAction" runat="server" ClientInstanceName="ddlAction">
                                <Items>
                                    <dx:ListEditItem Value="0" Selected="true" Text="-- Vælg handling --" />
                                    <dx:ListEditItem Value="1" Text="Manuel redigering" />
                                    <dx:ListEditItem Value="2" Text="Tilføj/rediger note" />
                                    <dx:ListEditItem Value="3" Text="Vis kørselsskema" />
                                    <dx:ListEditItem Value="4" Text="Anmod valgte om godkendelse (email)" />
                                    <dx:ListEditItem Value="5" Text="Angiv valgte som godkendte" />
                                    <dx:ListEditItem Value="6" Text="Fjern godkendelse fra valgte" />
                                    <dx:ListEditItem Value="7" Text="Google map/streetview" />
                                    <dx:ListEditItem Value="8" Text="Vis rute" />
                                    <dx:ListEditItem Value="10" Text="Bloker valgte" />
                                </Items>
                            </dx:ASPxComboBox>
                            &nbsp;
                            <dx:ASPxButton ID="btnSubmitAction" runat="server" Text="Udfør" AutoPostBack="False" UseSubmitBehavior="False">
                                <ClientSideEvents Click="function(s, e) { PlanningActionClicked(); }" />
                            </dx:ASPxButton>
                        </td>
                    </tr>
                    <tr>
                        <td valign="top">
                            <dx:ASPxGridView ID="gvServiceCarCapacity" runat="server" 
                                KeyFieldName="ServiceCarScheduleDetailId" 
                                AutoGenerateColumns="False" ClientInstanceName="GridView"
                                OnHtmlRowPrepared="gvServiceCarCapacity_HtmlRowPrepared" 
                                OnCustomCallback="gvServiceCarCapacity_CustomCallback">
                                <ClientSideEvents EndCallback="function(s, e) { DrillDownWindow.SetClientWindowSize(-1, 100, 100) }" />
                                <SettingsBehavior ProcessFocusedRowChangedOnServer="false" AllowFocusedRow="true" />
                                <Columns>
                                    <dx:GridViewCommandColumn ShowSelectCheckbox="True" VisibleIndex="0">
                                            <HeaderTemplate>
                                                <input type="checkbox" onclick="GridView.SelectAllRowsOnPage(this.checked);" style="vertical-align:middle;" title="Vælg/Fravælg alle linjer på siden"></input>
                                            </HeaderTemplate>
                                            <HeaderStyle Paddings-PaddingTop="1" Paddings-PaddingBottom="1" 
                                                HorizontalAlign="Center">
                                            <Paddings PaddingTop="1px" PaddingBottom="1px"></Paddings>
                                            </HeaderStyle>
                                    </dx:GridViewCommandColumn>
                                    <dx:GridViewDataColumn VisibleIndex="0">
                                        <DataItemTemplate>
                                            <dx:ASPxButton ID="btnDelete" runat="server" ClientInstanceName="btnDelete" Text="Slet" ToolTip="Klik for at slette booket servicekørsel" AutoPostBack="false"
                                                ClientSideEvents-Click='<%# "function(s, e) { DeleteBookedService(" + Container.KeyValue + "); }" %>'>
                                            </dx:ASPxButton>                                           
                                        </DataItemTemplate>
                                    </dx:GridViewDataColumn>
                                    <dx:GridViewDataHyperLinkColumn FieldName="CustomerId" VisibleIndex="3" Caption="Kundenr">
                                        <PropertiesHyperLinkEdit NavigateUrlFormatString="~/View/CustomerView/EditCustomerData.aspx?CustomerId={0}" TextField="CustomerId" Target="_blank">
                                        </PropertiesHyperLinkEdit>
                                    </dx:GridViewDataHyperLinkColumn>
                                    <dx:GridViewDataTextColumn FieldName="ServiceCarScheduleDetailId" Visible="false" VisibleIndex="0" />
                                    <dx:GridViewDataTextColumn FieldName="ScheduleDate" Visible="false" VisibleIndex="0" />
                                    <dx:GridViewDataTextColumn FieldName="ServiceCarId" Visible="false" VisibleIndex="0" />
                                    <dx:GridViewDataTextColumn FieldName="ToLongitude" Visible="false" VisibleIndex="0" />
                                    <dx:GridViewDataTextColumn FieldName="ToLatitude" Visible="false" VisibleIndex="0" />
                                    <dx:GridViewDataTextColumn FieldName="CarId" Visible="false" VisibleIndex="0" />
                                    <dx:GridViewDataTextColumn FieldName="ContainerId" Visible="false" VisibleIndex="0" />
                                    <dx:GridViewDataTextColumn FieldName="ScheduleDetailTypeId" Visible="false" VisibleIndex="0" />
                                    <dx:GridViewDataTextColumn FieldName="Note" Visible="false" VisibleIndex="0" />
                                    <dx:GridViewDataTextColumn Caption="Start" FieldName="StartTime" VisibleIndex="0" />
                                    <dx:GridViewDataTextColumn Caption="Slut" FieldName="EndTime" VisibleIndex="1" />
                                    <dx:GridViewDataTextColumn Caption="Navn" FieldName="Name" VisibleIndex="2" />
                                    <dx:GridViewDataTextColumn Caption="Adresse" FieldName="ToAddress" VisibleIndex="3" />
                                    <dx:GridViewDataTextColumn Caption="Postnr" FieldName="ToZipCode" VisibleIndex="4" />
                                    <dx:GridViewDataTextColumn Caption="By" FieldName="ToCity" VisibleIndex="5" />
                                    <dx:GridViewDataTextColumn Caption="Telefon1" FieldName="Phone1" VisibleIndex="6" />
                                    <dx:GridViewDataTextColumn Caption="Reg.nr." FieldName="RegistrationNumber" VisibleIndex="7" />
                                    <dx:GridViewDataTextColumn Caption="Bil" FieldName="CarBrandDescription" VisibleIndex="7" />
                                    <dx:GridViewDataTextColumn FieldName="CustomerConfirmed" VisibleIndex="8" Visible="false" />
                                    <dx:GridViewDataColumn>
                                        <DataItemTemplate>
                                            <dx:ASPxImage ID="imgNote" Visible='<%# (Convert.ToString(Eval("Note")) != "") %>' ImageUrl="~/Images/Tiny/about.png" runat="server">
                                                <ClientSideEvents Click="function(s, e) { ShowNote(); }" />
                                            </dx:ASPxImage>
                                        </DataItemTemplate>
                                    </dx:GridViewDataColumn>
                                    <dx:GridViewDataColumn>
                                        <DataItemTemplate>
                                            <dx:ASPxButton ID="btnInsert" runat="server" ClientInstanceName="btnInsert" Text="+" ToolTip="Klik for at book valgte bil i dette tidsrum" AutoPostBack="false"
                                                ClientSideEvents-Click='<%# "function(s, e) { BookService(" + Container.KeyValue + "); }" %>'>
                                            </dx:ASPxButton>                                           
                                        </DataItemTemplate>
                                    </dx:GridViewDataColumn>
                                </Columns>
                                <SettingsLoadingPanel Mode="ShowOnStatusBar" />
                                <Styles>
                                    <Header ImageSpacing="5px" SortingImageSpacing="5px" />
                                </Styles>
                            </dx:ASPxGridView>
                        </td>
                        <td valign="top">
                            <b>Opret booking</b><br />
                            <dx:ASPxCheckBox ID="cbSecondaryAddress" ClientInstanceName="cbSecondaryAddress" runat="server" Text="Brug sekundær adresse">
                                <%--<ClientSideEvents CheckedChanged="function(s, e) { UseSecondaryAddress(); }" />--%>
                            </dx:ASPxCheckBox>
                            <dx:ASPxCheckBox ID="cbCustomerConfirmed" ClientInstanceName="cbCustomerConfirmed" runat="server" Text="Kunde godkendt">
                            </dx:ASPxCheckBox>
                            <%--<asp:CheckBox ID="cbSecondaryAddress" runat="server" Text="Brug sekundær adresse" /><br />--%>
                            <%--<asp:CheckBox ID="cbCustomerConfirmed" runat="server" Text="Kunde godkendt" /><br />--%>
                            <asp:TextBox ID="txtNote" runat="server" TextMode="MultiLine" Height="50px" Width="170px"></asp:TextBox><br />
                            <%--<asp:CheckBox ID="cbOtherAddress" runat="server" Text="Anden adresse" /><br />--%>
                            <dx:ASPxCheckBox ID="cbOtherAddress" ClientInstanceName="cbOtherAddress" runat="server" Text="Brug anden adresse">
                                <%--<ClientSideEvents CheckedChanged="function(s, e) { UseOtherAddress(); }" />--%>
                            </dx:ASPxCheckBox>
                            <dx:ASPxTextBox ID="txtOtherAddress" ClientInstanceName="txtOtherAddress" NullText="Adresse" runat="server" Width="170px">
                                <%--<ValidationSettings RequiredField-IsRequired="true" RequiredField-ErrorText="Udfyld anden adresse"></ValidationSettings>--%>
                            </dx:ASPxTextBox>
                            <dx:ASPxTextBox ID="txtOtherZipCode" ClientInstanceName="txtOtherZipCode" NullText="Postnr" runat="server" Width="170px">
                                <%--<ValidationSettings RequiredField-IsRequired="true" RequiredField-ErrorText="Udfyld anden postnr"></ValidationSettings>--%>
                            </dx:ASPxTextBox>
                            <dx:ASPxTextBox ID="txtOtherCity" ClientInstanceName="txtOtherCity" NullText="By" runat="server" Width="170px">
                                <%--<ValidationSettings RequiredField-IsRequired="true" RequiredField-ErrorText="Udfyld anden by"></ValidationSettings>--%>
                            </dx:ASPxTextBox>
                            <hr />
                            <asp:Panel ID="pCreateNewTimeslot" runat="server" Visible="true">
                                <b>Opret "timeslots"</b><br />
                                <asp:Label ID="lblDuration" runat="server" Text="Længde (min)"></asp:Label><br />
                                <dx:ASPxTextBox ID="txtDuration" ClientInstanceName="txtDuration" runat="server" Width="170px">
                                    <ValidationSettings CausesValidation="true" 
                                        ValidationGroup="GenerateSingleTimeslot" RequiredField-IsRequired="true" 
                                        RequiredField-ErrorText="Venligst angiv tidslængde for kørselstid" 
                                        ErrorDisplayMode="ImageWithTooltip" >
<RequiredField IsRequired="True" ErrorText="Venligst angiv tidsl&#230;ngde for k&#248;rselstid"></RequiredField>
                                    </ValidationSettings>
                                </dx:ASPxTextBox>
                                <br />
                                <asp:Label ID="lblOverlap" runat="server" Text="Overlap til forrige (min)"></asp:Label><br />
                                <dx:ASPxTextBox ID="txtOverlap" ClientInstanceName="txtOverlap" runat="server" Width="170px">
                                    <ValidationSettings CausesValidation="true" 
                                        ValidationGroup="GenerateSingleTimeslot" RequiredField-IsRequired="true" 
                                        RequiredField-ErrorText="Venligst angiv overlap tid" 
                                        ErrorDisplayMode="ImageWithTooltip" >
<RequiredField IsRequired="True" ErrorText="Venligst angiv overlap tid"></RequiredField>
                                    </ValidationSettings>
                                </dx:ASPxTextBox>
                                <br />
                                <%--<asp:Label ID="lblType" runat="server" Text="Type"></asp:Label><br />
                                <dx:ASPxComboBox ID="ddlType" ClientInstanceName="ddlType" runat="server">
                                </dx:ASPxComboBox>
                                <br />--%>
                                <dx:ASPxButton ID="btnSaveTimeslot" runat="server" Text="Gem" AutoPostBack="False" UseSubmitBehavior="False">
                                    <ClientSideEvents Click="function(s, e) { CreateSingleTimeslot() }" />
                                </dx:ASPxButton>
                            </asp:Panel>

                            <dx:ASPxCallback ID="callCreateSingleTimeslot" ClientInstanceName="callCreateSingleTimeslot" runat="server" OnCallback="callCreateSingleTimeslot_Callback">
                                <ClientSideEvents CallbackError="CallBackError" CallbackComplete="OnCallbackCreateSingleTimeslotComplete" />
                            </dx:ASPxCallback>
                        </td>
                    </tr>
                </table>
            </dx:PopupControlContentControl>
        </ContentCollection>
    </dx:ASPxPopupControl>

    <!-- Modalpopup: PlanningAction forms -->
    <dx:ASPxPopupControl ID="pcPlanningActionWindows" Modal="false" runat="server" Height="1px" AutoUpdatePosition="true"
        PopupHorizontalAlign="WindowCenter" PopupVerticalAlign="WindowCenter" 
        AllowDragging="True" ClientInstanceName="pcPlanningActionWindows" Left="200" Top="200"
        CloseAction="CloseButton" Width="153px" HeaderText="Noter">
        <ContentCollection>
            <dx:PopupControlContentControl ID="PopupControlContentControl2" runat="server">
                <!-- User panel for Googleview -->
                <dx:ASPxPanel ID="pGoogleView" runat="server" Width="100%" ClientInstanceName="pGoogleView" Visible="true">
                    <PanelCollection>
                        <dx:PanelContent runat="server" ID="GoogleViewPanelContent">
                            <table width="610px" border="0" cellspacing="5px" cellpadding="0px">
                                <tr>
                                    <td>
                                        <div id="map_canvas" style="width: 300px; height: 300px"></div>
                                    </td>
                                    <td>
                                        <div id="pano" style="width: 300px; height: 300px;"></div>
                                    </td>
                                </tr>
                            </table>
                        </dx:PanelContent>
                    </PanelCollection>
                </dx:ASPxPanel>

                <!-- User panel for Google direction -->
                <dx:ASPxPanel ID="pGoogleDirection" runat="server" Width="100%" ClientInstanceName="pGoogleDirection" Visible="true">
                    <PanelCollection>
                        <dx:PanelContent runat="server" ID="PanelContent1">
                            <table border="0" cellspacing="5px" cellpadding="0px">
                                <tr>
                                    <td>
                                        <div id="directionmap_canvas" style="width: 300px; height: 300px"></div>
                                    </td>
                                    <td>
                                        <div id="directions_panel" style="width: 300px; height: 300px"></div>
                                    </td>
                                </tr>
                            </table>
                        </dx:PanelContent>
                    </PanelCollection>
                            
                </dx:ASPxPanel>
            </dx:PopupControlContentControl>
        </ContentCollection>
    </dx:ASPxPopupControl>
                                                
    <!-- Modalpopup: Show planning note -->
    <dx:ASPxPopupControl ID="pcPlanningNote" Modal="true" runat="server" Height="1px" AutoUpdatePosition="true"
        PopupHorizontalAlign="WindowCenter" PopupVerticalAlign="WindowCenter" 
        AllowDragging="True" ClientInstanceName="pcPlanningNote" Left="200" Top="200"
        CloseAction="CloseButton" Width="153px" HeaderText="Note">
        <ContentCollection>
            <dx:PopupControlContentControl ID="PopupControlContentControl1" runat="server">
                <!-- User Interface for editing Note -->
                <dx:ASPxMemo ID="txtPlanningNote" ClientInstanceName="txtPlanningNote" runat="server" Height="200px" Width="300px">
                </dx:ASPxMemo>
                <br />
                <dx:ASPxButton ID="btnSavePlanningNote" ClientInstanceName="btnSavePlanningNote" runat="server" Text="Gem note" AutoPostBack="False" UseSubmitBehavior="False">
                    <ClientSideEvents Click="function(s, e) { SaveNoteClicked(); }" />
                </dx:ASPxButton>
            </dx:PopupControlContentControl>
        </ContentCollection>
    </dx:ASPxPopupControl>

    <!-- Modalpopup: Show manual edit -->
    <dx:ASPxPopupControl ID="pcPlanningManualEdit" Modal="true" runat="server" Height="1px" AutoUpdatePosition="true"
        PopupHorizontalAlign="WindowCenter" PopupVerticalAlign="WindowCenter" 
        AllowDragging="True" ClientInstanceName="pcPlanningManualEdit" Left="200" Top="200"
        CloseAction="CloseButton" Width="153px" HeaderText="Rediger">
        <ContentCollection>
            <dx:PopupControlContentControl ID="PopupControlContentControl3" runat="server">
                <!-- User Interface for manual editing -->
                <table>
                    <tr>
                        <td>Starttid</td>
                        <td>
                            <dx:ASPxTextBox ID="txtStartTime" ClientInstanceName="txtStartTime" runat="server" Width="170px">
                            </dx:ASPxTextBox>
                        </td>
                    </tr>
                    <tr>
                        <td>Sluttid</td>
                        <td>
                            <dx:ASPxTextBox ID="txtEndTime" ClientInstanceName="txtEndTime" runat="server" Width="170px">
                            </dx:ASPxTextBox>
                        </td>
                    </tr>
                    <tr>
                        <td>Adresse</td>
                        <td>
                            <dx:ASPxTextBox ID="txtAddress" ClientInstanceName="txtAddress" runat="server" Width="170px">
                            </dx:ASPxTextBox>
                        </td>
                    </tr>
                    <tr>
                        <td>Postnr og by</td>
                        <td>
                            <dx:ASPxTextBox ID="txtZipCode" ClientInstanceName="txtZipCode" runat="server" Width="50px">
                            </dx:ASPxTextBox>
                            <dx:ASPxTextBox ID="txtCity" ClientInstanceName="txtCity" runat="server" Width="150px">
                            </dx:ASPxTextBox>
                        </td>
                    </tr>
                    <tr>
                        <td>
                            Latitude / Longitude
                        </td>
                        <td>
                            <dx:ASPxTextBox ID="txtLatitude" Enabled="false" ClientInstanceName="txtLatitude" runat="server" Width="50px">
                            </dx:ASPxTextBox>
                            <dx:ASPxTextBox ID="txtLongitude" Enabled="false" ClientInstanceName="txtLongitude" runat="server" Width="50px">
                            </dx:ASPxTextBox>
                            <dx:ASPxButton ID="btnGetLatLong" ClientInstanceName="btnGetLatLong" runat="server" Text="Hent koordinator" AutoPostBack="False" UseSubmitBehavior="False">
                                <ClientSideEvents Click="function(s, e) { GetLatLong(); }" />
                            </dx:ASPxButton>
                            <table  bgcolor="#FFFFCC" width="300">
                                <tr>
                                <td><b>Latitude</b></td>
                                <td><b>Longitude</b></td>
                                </tr>
                                <tr>
                                <td id="lat"></td>
                                <td id="lng"></td>
                                </tr>
                            </table>

                        </td>
                    </tr>
                </table>
                <br />
                <dx:ASPxButton ID="btnSaveServiceDetail" ClientInstanceName="btnSaveServiceDetail" runat="server" Text="Gem" AutoPostBack="False" UseSubmitBehavior="False">
                    <ClientSideEvents Click="function(s, e) { SaveServiceDetailClicked(); }" />
                </dx:ASPxButton>
            </dx:PopupControlContentControl>
        </ContentCollection>
    </dx:ASPxPopupControl>

    <!-- Modalpopup: Show create service booking -->
    <dx:ASPxPopupControl ID="pcCreateServiceBooking" Modal="true" runat="server" Height="1px" AutoUpdatePosition="true"
        PopupHorizontalAlign="WindowCenter" PopupVerticalAlign="WindowCenter" 
        AllowDragging="True" ClientInstanceName="pcCreateServiceBooking" Left="200" Top="200"
        CloseAction="CloseButton" Width="153px" HeaderText="Opret service booking">
        <ContentCollection>
            <dx:PopupControlContentControl ID="PopupControlContentControl5" runat="server">
                <!-- User Interface for manual editing -->

                1. Service kørsel
                1a. Hent/bring hjul for valgt kunde - brug primær, sekundær eller 3. adresse
                1b. Hent hjul hos leverandør (dropdownliste med prefixet adresser)
                2. Blokeret

                <table>
                    <tr>
                        <td>Type</td>
                        <td>
                            <dx:ASPxComboBox ID="ddlServiceBookingType" ClientInstanceName="ddlServiceBookingType" runat="server">
                                <Items>
                                    <dx:ListEditItem Value="1" Selected="true" Text="Servicekørsel" />
                                    <dx:ListEditItem Value="3" Text="Blok valgte" />
                                </Items>
                                <ClientSideEvents SelectedIndexChanged="function(s, e) { UpdateOtherBookingType()  }" />
                            </dx:ASPxComboBox>
                        </td>
                    </tr>
                    <tr>
                        <td>Sluttid</td>
                        <td>
                            <dx:ASPxTextBox ID="ASPxTextBox2" ClientInstanceName="txtEndTime" runat="server" Width="170px">
                            </dx:ASPxTextBox>
                        </td>
                    </tr>
                    <tr>
                        <td>Adresse</td>
                        <td>
                            <dx:ASPxTextBox ID="ASPxTextBox3" ClientInstanceName="txtAddress" runat="server" Width="170px">
                            </dx:ASPxTextBox>
                        </td>
                    </tr>
                    <tr>
                        <td>Postnr og by</td>
                        <td>
                            <dx:ASPxTextBox ID="ASPxTextBox4" ClientInstanceName="txtZipCode" runat="server" Width="50px">
                            </dx:ASPxTextBox>
                            <dx:ASPxTextBox ID="ASPxTextBox5" ClientInstanceName="txtCity" runat="server" Width="150px">
                            </dx:ASPxTextBox>
                        </td>
                    </tr>
                    <tr>
                        <td>
                            Latitude / Longitude
                        </td>
                        <td>
                            <dx:ASPxTextBox ID="ASPxTextBox6" Enabled="false" ClientInstanceName="txtLatitude" runat="server" Width="50px">
                            </dx:ASPxTextBox>
                            <dx:ASPxTextBox ID="ASPxTextBox7" Enabled="false" ClientInstanceName="txtLongitude" runat="server" Width="50px">
                            </dx:ASPxTextBox>
                            <dx:ASPxButton ID="ASPxButton1" ClientInstanceName="btnGetLatLong" runat="server" Text="Hent koordinator" AutoPostBack="False" UseSubmitBehavior="False">
                                <ClientSideEvents Click="function(s, e) { GetLatLong(); }" />
                            </dx:ASPxButton>
                            <table  bgcolor="#FFFFCC" width="300">
                                <tr>
                                <td><b>Latitude</b></td>
                                <td><b>Longitude</b></td>
                                </tr>
                                <tr>
                                <td id="Td1"></td>
                                <td id="Td2"></td>
                                </tr>
                            </table>

                        </td>
                    </tr>
                </table>
                <br />
                <dx:ASPxButton ID="btnSaveOtherBookingDetail" ClientInstanceName="btnSaveOtherBookingDetail" runat="server" Text="Gem" AutoPostBack="False" UseSubmitBehavior="False">
                    <ClientSideEvents Click="function(s, e) { SaveOtherBookingClicked(); }" />
                </dx:ASPxButton>
            </dx:PopupControlContentControl>
        </ContentCollection>
    </dx:ASPxPopupControl>

    <!-- Modalpopup: Create timeslots -->
    <dx:ASPxPopupControl ID="pcCreateTimeslots" Modal="true" runat="server" Height="1px" AutoUpdatePosition="true"
        PopupHorizontalAlign="WindowCenter" PopupVerticalAlign="WindowCenter" 
        AllowDragging="True" ClientInstanceName="pcCreateTimeslots" Left="200" Top="200"
        CloseAction="CloseButton" Width="300px" HeaderText="Opret tomme kørselstider">
        <ClientSideEvents PopUp="function(s, e) { cbPanelCreateTimeslots.PerformCallback() }" />
        <ContentCollection>
            <dx:PopupControlContentControl ID="PopupControlContentControl4" runat="server">
                <dx:ASPxCallbackPanel ID="cbPanelCreateTimeslots" ClientInstanceName="cbPanelCreateTimeslots" runat="server" Width="100%" 
                    OnCallback="cbPanelCreateTimeslots_OnCallback">
                    <PanelCollection>
                        <dx:PanelContent>
                            <table>
                                <tr>
                                    <td>
                                        <asp:Label ID="lblDate" runat="server" Text="Dato"></asp:Label>
                                    </td>
                                    <td>
                                        <asp:Label ID="lblServiceCar" runat="server" Text="Bil"></asp:Label>
                                    </td>
                                    <td>
                                        <asp:Label ID="lblStartingTime" runat="server" Text="Start-/sluttid"></asp:Label>        
                                    </td>
                                    <td>
                                        <asp:Label ID="lblSlotInterval" runat="server" Text="Slot interval og overlap)"></asp:Label>
                                    </td>
                                    <td rowspan="2">
                                        <dx:ASPxButton ID="btnCompleteTimeslotGeneration" runat="server" Text="Gem" AutoPostBack="False" UseSubmitBehavior="False" ValidationGroup="GenerateTimeslot">
                                            <ClientSideEvents Click="function(s, e) { SaveCreateTimeslots() }" />
                                        </dx:ASPxButton>    
                                    </td>
                                </tr>
                                <tr>
                                    <td valign="top">
                                        <dx:ASPxComboBox ID="ddlDate" ClientInstanceName="ddlDate" runat="server">
                                            <ValidationSettings CausesValidation="true" ValidationGroup="GenerateTimeslot" RequiredField-IsRequired="true" RequiredField-ErrorText="Venligst vælg dato" ErrorDisplayMode="ImageWithTooltip" />
                                        </dx:ASPxComboBox>
                                        <dx:ASPxCheckBox ID="cbSelectedWholePeriod" ClientInstanceName="cbSelectedWholePeriod" runat="server" Text="Opret for hele perioden" Checked="false">
                                        </dx:ASPxCheckBox>
                                        <%--<dx:ASPxRadioButtonList ID="rbtnDate" ClientInstanceName="rbtnDate" runat="server"> 
                                        </dx:ASPxRadioButtonList>--%>
                                    </td>
                                    <td valign="top">
                                        <dx:ASPxRadioButtonList ID="rbtnServiceCar" ClientInstanceName="rbtnServiceCar" runat="server">
                                            <ValidationSettings CausesValidation="true" ValidationGroup="GenerateTimeslot" RequiredField-IsRequired="true" RequiredField-ErrorText="Venligst vælg en servicebil" ErrorDisplayMode="ImageWithTooltip" />
                                        </dx:ASPxRadioButtonList>
                                    </td>
                                    <td valign="top">
                                        <dx:ASPxTextBox ID="txtStartingTime" ClientInstanceName="txtStartingTime" runat="server" Width="50px" NullText="Starttid - ex. 8:00">
                                            <ValidationSettings CausesValidation="true" ValidationGroup="GenerateTimeslot" RequiredField-IsRequired="true" RequiredField-ErrorText="Venligst angiv startid" ErrorDisplayMode="ImageWithTooltip" />
                                        </dx:ASPxTextBox>
                                        <br />
                                        <dx:ASPxTextBox ID="txtLatestEndTime" ClientInstanceName="txtLatestEndTime" runat="server" Width="50px" NullText="Sluttid - ex. 16:00">
                                            <ValidationSettings CausesValidation="true" ValidationGroup="GenerateTimeslot" RequiredField-IsRequired="true" RequiredField-ErrorText="Venligst angiv senest sluttid" ErrorDisplayMode="ImageWithTooltip" />
                                        </dx:ASPxTextBox>
                                    </td>
                                    <td valign="top">
                                        <dx:ASPxTextBox ID="txtSlotInterval" ClientInstanceName="txtSlotInterval" runat="server" Width="50px" NullText="Interval i min. - ex. 45">
                                            <ValidationSettings CausesValidation="true" ValidationGroup="GenerateTimeslot" RequiredField-IsRequired="true" RequiredField-ErrorText="Venligst angiv tidslængde for kørselstid" ErrorDisplayMode="ImageWithTooltip" />
                                        </dx:ASPxTextBox>
                                        <br />
                                        <dx:ASPxTextBox ID="txtGenerateTimeslotOverlap" ClientInstanceName="txtGenerateTimeslotOverlap" runat="server" Width="170px" NullText="Overlap forrige - ex. 30">
                                            <ValidationSettings CausesValidation="true" ValidationGroup="GenerateTimeslot" RequiredField-IsRequired="true" RequiredField-ErrorText="Venligst angiv overlap" ErrorDisplayMode="ImageWithTooltip" />
                                        </dx:ASPxTextBox>        
                                    </td>
                                </tr>
                            </table>
                        </dx:PanelContent>
                    </PanelCollection>
                </dx:ASPxCallbackPanel>

                <dx:ASPxCallback ID="callBackCreateTimeslots" ClientInstanceName="callBackCreateTimeslots" runat="server" OnCallback="callBackCreateTimeslots_Callback">
                    <ClientSideEvents CallbackError="CallBackError" CallbackComplete="OnCallbackCreateTimeslotsComplete" />
                </dx:ASPxCallback>

            </dx:PopupControlContentControl>
        </ContentCollection>
    </dx:ASPxPopupControl>

       

</asp:Content>
